package dialogos;
import java.awt.BorderLayout;
import java.awt.FlowLayout;
import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;
import java.util.Hashtable;
import java.util.List;
import javax.swing.BorderFactory;

import javax.swing.ComboBoxModel;
import javax.swing.DefaultComboBoxModel;
import javax.swing.JComboBox;
import javax.swing.JFrame;
import javax.swing.JPanel;
import javax.swing.SwingUtilities;
import javax.swing.border.LineBorder;

import paneles.PanelProveedores;
import accesoADatos.AccesoADatos;
import datos.Proveedor;


/**
* This code was edited or generated using CloudGarden's Jigloo
* SWT/Swing GUI Builder, which is free for non-commercial
* use. If Jigloo is being used commercially (ie, by a corporation,
* company or business for any purpose whatever) then you
* should purchase a license for each developer using Jigloo.
* Please visit www.cloudgarden.com for details.
* Use of Jigloo implies acceptance of these licensing terms.
* A COMMERCIAL LICENSE HAS NOT BEEN PURCHASED FOR
* THIS MACHINE, SO JIGLOO OR THIS CODE CANNOT BE USED
* LEGALLY FOR ANY CORPORATE OR COMMERCIAL PURPOSE.
*/
public class ModifProvDialog extends javax.swing.JDialog {

	private PanelProveedores pProveedores;
	private JPanel jPanel;
	private JComboBox jComboBox;
	private Hashtable hash = new Hashtable();
	/**
	* Auto-generated main method to display this JDialog
	*/
	public static void main(String[] args) {
		SwingUtilities.invokeLater(new Runnable() {
			public void run() {
				JFrame frame = new JFrame();
				ModifProvDialog inst = new ModifProvDialog(frame);
				inst.setVisible(true);
			}
		});
	}
	
	public ModifProvDialog(JFrame frame) {
		super(frame,"Modificar Proveedor",true);
		initGUI();
	}
	
	private void initGUI() {
		try {
			{
				pProveedores = new PanelProveedores();
				getContentPane().add(pProveedores, BorderLayout.CENTER);
				pProveedores.setPreferredSize(new java.awt.Dimension(300, 300));
				pProveedores.setSize(380, 315);
				pProveedores.getBCancelar().addActionListener(new ActionListener() {
					public void actionPerformed(ActionEvent evt) {
						ModifProvDialog.this.dispose();
					}
				});
				pProveedores.getBAceptar().addActionListener(new ActionListener() {
					public void actionPerformed(ActionEvent evt) {
						Proveedor p = ModifProvDialog.this.pProveedores.getProveedor();
						Proveedor p1 = (Proveedor)ModifProvDialog.this.hash.get(ModifProvDialog.this.jComboBox.getSelectedItem().toString());
						p1.setCelular(p.getCelular());
						p1.setTelefono(p.getTelefono());
						p1.setCiudad(p.getCiudad());
						p1.setCp(p.getCp());
						p1.setDireccion(p.getDireccion());
						p1.setEmail(p.getEmail());
						p1.setNombre(p.getNombre());
						p1.setWeb(p.getWeb());
						AccesoADatos.getInstance().setObjeto(p1);
						ModifProvDialog.this.dispose();
					}
				});
			}
			{
				jPanel = new JPanel();
				FlowLayout jPanelLayout = new FlowLayout();
				jPanelLayout.setVgap(10);
				jPanel.setLayout(jPanelLayout);
				getContentPane().add(jPanel, BorderLayout.NORTH);
				jPanel.setPreferredSize(new java.awt.Dimension(304, 47));
				{
					List l = AccesoADatos.getInstance().getProveedores();
					for(int i=0; i<l.size(); i++)
						this.hash.put(l.get(i).toString(), l.get(i));
					ComboBoxModel jComboBoxModel = 
						new DefaultComboBoxModel(
								l.toArray());
					jComboBox = new JComboBox();
					jPanel.add(jComboBox);
					jComboBox.setModel(jComboBoxModel);
					this.pProveedores.setProveedor((Proveedor)this.hash.get(jComboBox.getItemAt(0).toString()));
					jComboBox.setPreferredSize(new java.awt.Dimension(150, 21));
					jComboBox.setBackground(new java.awt.Color(255,255,255));
					jComboBox.setBorder(new LineBorder(new java.awt.Color(0,0,0), 1, false));
					jComboBox.addActionListener(new ActionListener() {
						public void actionPerformed(ActionEvent evt) {
							ModifProvDialog.this.pProveedores.setProveedor((Proveedor)hash.get(jComboBox.getSelectedItem().toString()));
						}
					});
				}
			}
			pack();
			this.pProveedores.setProveedor((Proveedor)hash.get(jComboBox.getSelectedItem().toString()));
			this.setLocationRelativeTo(null);
			this.setVisible(true);
		} catch (Exception e) {
			e.printStackTrace();
		}
	}
}
